/*
 * Copyright 2018 Youchaoshi authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package common.widget;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.orhanobut.logger.Logger;

/**
 * 获取验证码倒计时，按钮封装
 */
public class UpdataGetCodeView extends CountDownTimer {
    private TextView mTextView;

    /**
     * 更新获取验证码视图
     *
     * @param textView          按钮
     * @param millisInFuture    总时常，一般为60S，1000*60
     * @param countDownInterval 间隔时间，1000毫秒
     */
    public UpdataGetCodeView(final Context mContext, TextView textView, long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
        this.mTextView = textView;
        Logger.i("发送短信手机号码>>>" + mTextView.getTag().toString());

//        new CurrencyOP(mContext).Sendsms(new OkGoFinishListener() {
//            @Override
//            public void onSuccess(String mStr, Object bean) {
//                PubStatusBean mBean = (PubStatusBean) bean;
//                Logger.i("UpdataGetCodeView>>>" + mBean.getMessage());
//                Toasty.normal(mContext,mBean.getMessage()).show();
//                start();//启动倒计时
//            }
//        }, mTextView.getTag().toString().trim());//获取验证码，不需要回调


    }

    @Override
    public void onTick(long millisUntilFinished) {
        mTextView.setClickable(false); //设置不可点击
        mTextView.setText(millisUntilFinished / 1000 + "秒");  //设置倒计时时间
    }

    @Override
    public void onFinish() {
        mTextView.setText("获取验证码");
        mTextView.setClickable(true);//重新获得点击
    }
}
